public class Solution2 {
    public ListNode swapPairs(ListNode head) {
        if(head == null || head.next == null) {
            return head;
        }
        ListNode newHead = new ListNode();
        ListNode prev = newHead;
        ListNode cur = head;
        ListNode next = cur.next;
        ListNode nnext = next.next;

        while(cur != null && next != null) {
            prev.next = next;
            next.next = cur;
            cur.next = nnext;

            prev = cur;
            cur = prev.next;
            if(cur != null) {
                next = cur.next;
            }

            if(next != null) {
                nnext = next.next;
            }
        }
        return newHead.next;
    }
}
